package com.czh.oss.config;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.czh.oss.adapter.StorageAdapter;
import com.czh.oss.adapter.impl.AliStorageAdapter;
import com.czh.oss.adapter.impl.MinioStorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文件服务适配器 TODO tip
 * @author caozaihui
 * @version 1.0
 * @since 2024/8/17 下午 11:01
 */
@Configuration
@RefreshScope//热更新注解
public class StorageConfig {

    @Value(value = "${storage.service.type}")
    private String storageType;


    @Bean
    public StorageAdapter storageAdapter(){
        return switch (storageType) {
            case "minio" -> new MinioStorageAdapter();
            case "aliyun" -> new AliStorageAdapter();
            default -> throw new IllegalArgumentException("未找到对应文件处理器");
        };
    }
}
